package com.fortune.common.spring.jackson.deserializer;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fortune.constants.enums.LogableEnum;

public class LogableEnumDeserializer extends JsonDeserializer<LogableEnum> {

	@Override
	public LogableEnum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
		JsonNode node = jp.getCodec().readTree(jp);  
		String value = node.toString();
		LogableEnum logableEnum;
		try {
			logableEnum = LogableEnum.valueOf(value);
		} catch (Exception e) {
			logableEnum = null;
		}
		
		return logableEnum;
	}

}
